<?php

use Illuminate\Database\Seeder;
use App\Models\Star;
use App\Models\Movie;
class ActorOrDirectorToMovieTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $stars = Star::pluck('id');
        $movies = Movie::all();
        foreach($movies as $movie) {
            $actors = $stars->random(rand(3,8));
            $directors = $stars->random(rand(1,2));
            $movie->directors()->sync($directors);
            $movie->actors()->sync($actors);
        }
    }
}
